/*
 * ContextListener.java
 *
 * Created on May 29, 2007, 4:17 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.src.computec.facturacion.listener;

import com.src.computec.facturacion.base.constantes.ConstantesGenerales;
import com.src.computec.facturacion.source.FacturacionSource;
import com.src.computec.radar.base.source.CoreSource;
import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author fsanchez
 */
public class ContextListener implements ServletContextListener {
    
  /**
     * ### Method from ServletContextListener ###
     * 
     * Called when a Web application is first ready to process requests
     * (i.e. on Web server startup and when a context is added or reloaded).
     * 
     * For example, here might be database connections established
     * and added to the servlet context attributes.
     * @param evt 
     */
    public void contextInitialized(ServletContextEvent evt) 
    {
        System.out.println("ContextListener Porlet Tarifas Admin: contextInitialized ************************");
        ConstantesGenerales constantes = ConstantesGenerales.getInstance();
        // String directorio_= "C:\\CargueArchivos\\"+ FacturacionSource.getInstance().getFacturacionSetupKey("pathArchivosTarifas");     
        String directorio_= CoreSource.getInstance().getUtilidadesSetupKey("folderCargueArchivos")+ FacturacionSource.getInstance().getFacturacionSetupKey("pathArchivosTarifas");     
        File dir_=new File(directorio_);
        if(dir_.isDirectory()){
            String[] listFiles_=dir_.list();
            for(int i=0;i<listFiles_.length;++i){
                //System.out.println("FILE:"+directorio_+"\\"+listFiles_[i]);
                File tmpFile=new File(directorio_+"/"+listFiles_[i]);
                tmpFile.delete();
            }
        }
       
    }
 
    /**
     * ### Method from ServletContextListener ###
     * 
     * Called when a Web application is about to be shut down
     * (i.e. on Web server shutdown or when a context is removed or reloaded).
     * Request handling will be stopped before this method is called.
     * 
     * For example, the database connections can be closed here.
     */
    public void contextDestroyed(ServletContextEvent evt) 
    {        
    }

    
}
